package com.huifer.wgx.controller;

import com.huifer.wgx.model.InteriorLineEntity;
import com.huifer.wgx.model.ResultPointEntity;
import com.huifer.wgx.pojo.CommonResult;
import com.huifer.wgx.service.ResultPointService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>Title : ResultPointController </p>
 * <p>Description :成果线</p>
 *
 * @author huifer
 * @date 2019-03-15
 */
@RestController
@RequestMapping("result_point")
@Api(tags = "ResultPointController", description = "成果点数据管理")
public class ResultPointController {

    @Autowired
    private ResultPointService resultPointService;

    private CommonResult commonResult = new CommonResult();


    @ApiOperation("内业点转换成成果点")
    @PostMapping("/inter_point_to_result")
    public ResponseEntity saveInterPoint(
            @RequestParam("work_id") Long workId,
            @RequestParam("personnel_id") Long personnelId
    ) {
        try {
            return ResponseEntity
                    .ok(commonResult
                            .success(resultPointService.inter2ResultPoint(workId, personnelId)));
        } catch (Exception e) {
            return ResponseEntity.badRequest().body(commonResult.fialed(e));
        }
    }


    @ApiOperation("创建一个成果点")
    @PostMapping("/save")
    public ResponseEntity saveInterLine(
            ResultPointEntity iPoint
    ) {
        try {
            return ResponseEntity
                    .ok(commonResult.success(resultPointService.saveOne(iPoint)));
        } catch (Exception e) {
            return ResponseEntity.badRequest().body(commonResult.fialed(e));
        }
    }

    @ApiOperation("更新一个成果点")
    @PutMapping("/update")
    public ResponseEntity updateInterLine(
            ResultPointEntity iPoint

    ) {
        try {
            return ResponseEntity
                    .ok(commonResult.success(resultPointService.updateIpoint(iPoint)));
        } catch (Exception e) {
            return ResponseEntity.badRequest().body(commonResult.fialed(e));
        }
    }


    @ApiOperation("查询所有成果点数据")
    @GetMapping("/find_all")
    public ResponseEntity findAll(
            @RequestParam("pagenum") Integer pageNum,
            @RequestParam("pagesize") Integer pageSize) {
        try {
            return ResponseEntity
                    .ok(commonResult.success(resultPointService.findAll(pageNum, pageSize)));
        } catch (Exception e) {
            return ResponseEntity.badRequest().body(commonResult.fialed(e));
        }
    }

    @ApiOperation("根据工程id查询成果点数据")
    @GetMapping("/find_by_work_id")
    public ResponseEntity findRtkByWorkId(
            @RequestParam("workid") Long workId,
            @RequestParam("pagenum") Integer pageNum,
            @RequestParam("pagesize") Integer pageSize) {
        try {
            return ResponseEntity
                    .ok(commonResult
                            .success(resultPointService.findByWorkId(pageNum, pageSize, workId)));
        } catch (Exception e) {
            return ResponseEntity.badRequest().body(commonResult.fialed(e));
        }
    }

    @ApiOperation("根据负责人id查询成果点数据")
    @GetMapping("/find_by_personnel_id")
    public ResponseEntity findByPersonnelId(
            @RequestParam("personnelid") Long personnelId,
            @RequestParam("pagenum") Integer pageNum,
            @RequestParam("pagesize") Integer pageSize) {
        try {
            return ResponseEntity
                    .ok(commonResult
                            .success(resultPointService
                                    .findByPersonnelId(personnelId, pageNum, pageSize)));
        } catch (Exception e) {
            return ResponseEntity.badRequest().body(commonResult.fialed(e));
        }
    }

}
